package ddd1;

public class work4 {
    public static void main(String[] args) {
        String s1 = "ccssabcddddwasfwegwegwer";
        String s2 = "sbabcddd";
        String s3 = longestString(s1, s2);
        System.out.println(s3);
    }
    public static String longestString(String word1, String word2) {
        int newI;
        String longestStr = "";
        int count=0;
        for (int i = 0; i < word1.length(); i++) {
            newI=i;
            int newCount =0;
            for (int j = 0; j < word2.length(); j++) {
                if (word1.charAt(newI) == word2.charAt(j)) {
                    newCount++;
                    newI++;
                }else{
                    newCount=0;
                }
            }
            if(newCount>count){
                count=newCount;
                longestStr=word1.substring(newI-count,newI);
            }
        }
        return longestStr;
    }
}
